<?php

if ($bInit === true)
{
	?>
	<script type="text/javascript">
	
	var baseIcon;
	var letter;
	var letteredIcon;
	var point;		
		
	function createMarker(point, html, letteredIcon) {
	  	var marker = new GMarker(point, { icon:letteredIcon });
	    GEvent.addListener(marker, "click", function() {
	    	marker.openInfoWindowHtml('<div align="left">' + html + '</div>');
	   	});
	    marker.icon = 'b';
	    // save the info we need to use later for the side_bar
	    return marker;
	}
	
	
	function add_icon_to_gmap(oMap, sTitle, sDesc, sLetter, sLatLong) {
		letteredIcon.image = 'http://www.google.com/mapfiles/marker' + sLetter + '.png';
			
		var aLatLong = sLatLong.split(',');
		
		var oDiv = document.createElement('div');
		var oBr = document.createElement('br');
		
		$(oDiv).html(sTitle).append(oBr).append(sDesc);
		
		point = new GLatLng($.trim(aLatLong[0]), $.trim(aLatLong[1])); 
		marker = createMarker(point, $(oDiv).html(), letteredIcon);
		
		$(oDiv).remove();
		
		oMap.addOverlay(marker);
	}	
	
	
	function make_gmap(sGmapCont, fGmapLat, fGmapLong, iGmapZoom) {

		var gmap;

		if (GBrowserIsCompatible()) {
        	gmap = new GMap2(document.getElementById(sGmapCont));
			gmap.setMapType(G_HYBRID_MAP); 
		    gmap.addControl(new GLargeMapControl());
		   	gmap.addControl(new GMapTypeControl());
		    gmap.enableContinuousZoom();
    		gmap.enableScrollWheelZoom();
			gmap.enableGoogleBar();
			
	        gmap.setCenter(new GLatLng(fGmapLat, fGmapLong), iGmapZoom);		
			
			baseIcon = new GIcon();
		    baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		    baseIcon.iconSize = new GSize(20, 34);
		    baseIcon.shadowSize = new GSize(37, 34);
		    baseIcon.iconAnchor = new GPoint(9, 34);
		    baseIcon.infoWindowAnchor = new GPoint(9, 2);
		    baseIcon.infoShadowAnchor = new GPoint(18, 25);
					
			letteredIcon = new GIcon(baseIcon);		
		}
		
		return gmap;
	}
		
	
	$(document).ready(
		function() {
		
			var oGmap;		
	<?php
} 
else if ($bInit === false)
{
	?>
	
	
		}
	);
	</script>	
	<?php
}
else 
{
	?>
	oGmap = make_gmap('gmap_cont_<?php echo $iGmapContId; ?>', <?php echo $oGmap->version_lat; ?>, <?php echo $oGmap->version_long; ?>, <?php echo $oGmap->version_zoom; ?>);
	
	<?php	
	
	$iGmapMarkers = $qGmapMarkers->num_rows();
	
	for ($i = 0; $i < $iGmapMarkers; $i++)
	{
		?>
		add_icon_to_gmap(oGmap, '<?php echo addslashes($qGmapMarkers->row($i)->marker_title); ?>', '<?php echo addslashes($qGmapMarkers->row($i)->marker_desc); ?>', '<?php echo addslashes($qGmapMarkers->row($i)->marker_icon); ?>', '<?php echo addslashes($qGmapMarkers->row($i)->marker_lat.', '.$qGmapMarkers->row($i)->marker_long); ?>');
		<?php	
	}
}

?>